package com.gtfrank.web.servlet.dao.impl;

import com.gtfrank.web.servlet.dao.IUserDao;
import com.gtfrank.web.servlet.pojo.User;
import com.gtfrank.web.servlet.util.BasicDao;

import java.util.List;

/**
 * @ProjectName: sudacoursetrainging
 * @ClassName: UserDaoImpl
 * @PackageName:com.gtfrank.web.servlet.dao.impl
 * @Description: 用户接口实现
 * @Author: frank
 * @Date: 2021/4/28 16:06
 * @Version v1.0
 */
public class UserDaoImpl implements IUserDao {
    @Override
    public User findUserByNameAndPassword(String name, String password) {
        User user = BasicDao.getObject(User.class,
                "select * from test_user where name=? and password=?",name,password);
        return user;
    }

    @Override
    public void addUser(User user) {
        BasicDao.updateData("insert into test_user(name,password) values(?,?)",user.getName(),user.getPassword());
    }

    @Override
    public List<User> findAll() {
        return BasicDao.getObjectToList(User.class,"select * from test_user");
    }

    @Override
    public void deleteUser(int id) {
        BasicDao.updateData("delete from test_user where id=?",id);
    }

    @Override
    public User findById(int id) {
        return BasicDao.getObject(User.class,"select * from test_user where id=?",id);
    }

    @Override
    public void updateUser(User user) {
        BasicDao.updateData("update test_user set name=?,password=? where id=?",user.getName()
        ,user.getPassword(),user.getId());
    }

    @Override
    public User findByName(String name) {
        return BasicDao.getObject(User.class,"select * from test_user where name=?",name);
    }

    @Override
    public List<User> findByLikeName(String name) {
        return null;
    }
}
